package com.jf.identity.entity;

import com.jf.identity.util.Params;

import java.io.Serializable;

/**
 * 一场考试的基本信息
 *
 * @author FCG
 */
public class ExamBaseParam implements Serializable {
    private static final long serialVersionUID = 6388469121108439528L;
    public final static String ORGCODE = "orgCode";
    public final static String EXAM_ID = "examId";
    public final static String EXAM_SESSION_NUM = "examSessionNum";
    public final static String LOGIC_EXAM_ROOM_NUM = "logicExamRoomNum";
    public final static String DEVICE_ID = "deviceId";
    private String orgCode;
    private String orgIdenCode;
    private String examId;
    private String examSessionNum;
    private String logicExamRoomNum;
    private String deviceId;

    private String examPlan;
    private String examSession;

    public static ExamBaseParam copyOf(ExamBaseParam examBaseParam) {
        if (examBaseParam == null) {
            return null;
        }
        ExamBaseParam copy = new ExamBaseParam();
        copy.setOrgIdenCode(examBaseParam.getOrgIdenCode());
        copy.setLogicExamRoomNum(examBaseParam.getLogicExamRoomNum());
        copy.setDeviceId(examBaseParam.getDeviceId());
        copy.setExamSessionNum(examBaseParam.getExamSessionNum());
        copy.setOrgCode(examBaseParam.getOrgCode());
        copy.setExamId(examBaseParam.getExamId());
        return copy;
    }

    public static void isBlank(ExamBaseParam examBaseParam) {
        Params.isBlank(examBaseParam, "考试信息");
    }

    public void validate(String... fields) {
        if (fields == null || fields.length == 0) {
            return;
        }
        for (String field : fields) {
            switch (field) {
                case ExamBaseParam.ORGCODE:
                    Params.isBlank(getOrgCode(), "机构代码");
                    if (getOrgCode().length() > 50) {
                        throw new IllegalArgumentException("机构代码小于50个字符");
                    }
                    break;
                case ExamBaseParam.EXAM_ID:
                    Params.isBlank(getExamId(), "考试计划");
                    if (getExamId().length() > 10) {
                        throw new IllegalArgumentException("考试计划小于10个字符");
                    }
                    break;
                case ExamBaseParam.EXAM_SESSION_NUM:
                    Params.isBlank(getExamSessionNum(), "考试场次");
                    if (getExamSessionNum().length() > 2) {
                        throw new IllegalArgumentException("考试场次小于2个字符");
                    }
                    if (Integer.parseInt(getExamSessionNum()) < 0) {
                        throw new IllegalArgumentException("考试场次>=0");
                    }
                    break;
                case ExamBaseParam.LOGIC_EXAM_ROOM_NUM:
                    Params.isBlank(getLogicExamRoomNum(), "逻辑考场号");
                    if (getLogicExamRoomNum().length() > 50) {
                        throw new IllegalArgumentException("逻辑考场号小于50个字符");
                    }
                    break;
                case ExamBaseParam.DEVICE_ID:
                    Params.isBlank(getDeviceId(), "设备编号");
                    if (getDeviceId().length() > 20) {
                        throw new IllegalArgumentException("设备id小于20个字符");
                    }
                    break;
                default:
                    break;
            }
        }
    }

    public String getOrgCode() {
        return orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    public String getOrgIdenCode() {
        return orgIdenCode;
    }

    public void setOrgIdenCode(String orgIdenCode) {
        this.orgIdenCode = orgIdenCode;
    }

    public String getExamId() {
        return examId == null ? examPlan : examId;
    }

    public void setExamId(String examId) {
        this.examId = examId;
    }

    public String getExamSessionNum() {
        return examSessionNum == null ? examSession : examSessionNum;
    }

    public void setExamSessionNum(String examSessionNum) {
        this.examSessionNum = examSessionNum;
    }

    public String getLogicExamRoomNum() {
        return logicExamRoomNum;
    }

    public void setLogicExamRoomNum(String logicExamRoomNum) {
        this.logicExamRoomNum = logicExamRoomNum;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getExamPlan() {
        return examPlan;
    }

    public void setExamPlan(String examPlan) {
        this.examPlan = examPlan;
    }

    public String getExamSession() {
        return examSession;
    }

    public void setExamSession(String examSession) {
        this.examSession = examSession;
    }

    @Override
    public String toString() {
        return "ExamBaseParam{" +
                "orgCode='" + orgCode + '\'' +
                ", orgIdenCode='" + orgIdenCode + '\'' +
                ", examId='" + examId + '\'' +
                ", examSessionNum='" + examSessionNum + '\'' +
                ", logicExamRoomNum='" + logicExamRoomNum + '\'' +
                ", deviceId='" + deviceId + '\'' +
                ", examPlan='" + examPlan + '\'' +
                ", examSession='" + examSession + '\'' +
                '}';
    }
}
